﻿using Appliaction.AppServices.DB;
using Appliaction.Dto.DB;
using Appliaction.IAppServices.DB;
using AutoMapper;
using Domain.Entitys.DB;
using Domain.IRepositorys.DB;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers.DB
{
    /// <summary>
    /// 库位控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]
    public class Db_warehouse_locationController : Controller
    {
        private readonly IMapper mapper;

        private readonly IDb_warehouse_locationServices  db_Warehouse_LocationServices;

        public Db_warehouse_locationController(IMapper _mapper, IDb_warehouse_locationServices db_Warehouse_LocationServices)
        {
            mapper = _mapper;
            this.db_Warehouse_LocationServices = db_Warehouse_LocationServices;
        }

        /// <summary>
        /// 库位分页查询(控制器)
        /// </summary>
        /// <param name="location_code">编码</param>
        /// <param name="location_name">名称</param>
        /// <param name="location_x_position">库位位置X</param>
        /// <param name="location_y_position">库位位置Y</param>
        /// <param name="location_z_position">库位位置Z</param>
        /// <param name="currentPage">当前页</param>
        /// <param name="pageSize">查询条数</param>
        /// <returns></returns>
        [HttpGet]
       public JsonResult Warehouse_locationfY(string zone_code, string ? location_code , string ? location_name, int  location_x_position, int  location_y_position, int location_z_position, int currentPage, int pageSize) { 
        return new JsonResult(db_Warehouse_LocationServices.Select_fy_warehouse_zone(zone_code, location_code, location_name, location_x_position, location_y_position, location_z_position, currentPage, pageSize));
        }

        /// <summary>
        /// 查询总条数(控制器)
        /// </summary>
        /// <param name="warehouse_name"></param>
        /// <returns></returns>
        [HttpGet]
       public int Warehouse_locationCount(string zone_code, string ?location_code, string ?location_name, int location_x_position, int location_y_position, int location_z_position) {
            return db_Warehouse_LocationServices.Select_count_warehouse_zone(zone_code, location_code, location_name, location_x_position, location_y_position, location_z_position);
        }

        /// <summary>
        /// 修改库位 冻结状态(控制器)
        /// </summary>
        /// <param name="id"></param>
        /// <param name="location_freeze"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<int> warehouselocationFrozenstate(int id, char location_freeze)
        {
           return db_Warehouse_LocationServices.warehouse__location_Frozenstate(id, location_freeze);
        }

        /// <summary>
        /// 库位编码唯一性验证
        /// </summary>
        /// <param name="warehouse_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public Task<int> WarehouseLocation_code_judgment(string location_code,string zone_code)
        {
            return db_Warehouse_LocationServices.Warehouse_Location_code_judgment(location_code, zone_code);
        }
        /// <summary>
        /// 库位名称唯一性检测
        /// </summary>
        /// <param name="warehouse_name"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public Task<int> WarehouseLocation_name_judgment(string location_name, string zone_code)
        {
            return db_Warehouse_LocationServices.Warehouse_Location_name_judgment(location_name,zone_code);
        }

        /// <summary>
        /// 添加库位
        /// </summary>
        /// <param name="db_Warehouse_LocationAddDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public async Task<JsonResult> warehouse_location_Insert(Db_Warehouse_locationAddDto db_Warehouse_LocationAddDto)
        {
            return new JsonResult(await db_Warehouse_LocationServices.warehouse_location_Add(db_Warehouse_LocationAddDto));
        }


        /// <summary>
        /// 修改库位信息
        /// </summary>
        /// <param name="db_Warehouse_LocationUpdateDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public async Task<JsonResult> warehouse_locationUpdate(Db_Warehouse_locationUpdateDto db_Warehouse_LocationUpdateDto)
        {
            return new JsonResult(await db_Warehouse_LocationServices.warehouse__location_Update(db_Warehouse_LocationUpdateDto));
        }


        /// <summary>
        /// 库位删除
        /// </summary>
        /// <param name="zone_code"></param>
        /// <param name="location_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public Task<int> warehouselocation_tombstone(string zone_code, string location_code)
        {
            return db_Warehouse_LocationServices.warehouse_location_tombstone(zone_code, location_code);
        }


        /// <summary>
        /// 查询库位
        /// </summary>
        /// <param name="zone_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public JsonResult warehouse_locationAsync(string ? zone_code)
        {
            return new JsonResult(db_Warehouse_LocationServices.warehouse_location_Async(zone_code));
        }


        /// <summary>
        /// 判断库位的添加是否大于库区的容量
        /// </summary>
        /// <param name="warehouse_code"></param>
        /// <param name="zone_capacity"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<int> Warehouselocation_Capacity_judgment(string zone_code, int location_max_capacity)
        {

            return db_Warehouse_LocationServices.Warehouselocation_Capacity_judgment(zone_code, location_max_capacity);
        }


        /// <summary>
        /// 结构编码查询仓库信息
        /// </summary>
        /// <param name="warehouse_code"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult Warehouse_location_By_Select_Async_code(string zone_code, string location_code)
        {

            return new JsonResult(db_Warehouse_LocationServices.Warehouse_location_By_Select_Async_code(zone_code, location_code));
        }


        /// <summary>
        /// 修改查询仓库名称
        /// </summary>
        /// <param name="location_name"></param>
        /// <param name="zone_code"></param>
        /// <param name="location_code"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<int> Warehouse_Location_name_UpdateJudgment(string location_name, string zone_code, string location_code)
        {

            return db_Warehouse_LocationServices.Warehouse_Location_name_UpdateJudgment(location_name, zone_code, location_code);
        }


        /// <summary>
        /// 修改的容量判断
        /// </summary>
        /// <param name="zone_code"></param>
        /// <param name="location_code"></param>
        /// <param name="new_location_max_capacity"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<int> Warehouselocation_Capacity_UpdateJudgment(string zone_code, string location_code, int new_location_max_capacity)
        {

            return db_Warehouse_LocationServices.Warehouselocation_Capacity_UpdateJudgment(zone_code, location_code, new_location_max_capacity);
        }
    }
}
